import 'package:cbec_app/components/base/base_function.dart';
import 'package:cbec_app/components/base/left_nav_menu_item.dart';
import 'package:cbec_app/components/common/common_style.dart';
import 'package:cbec_app/components/base/base_nav_bar.dart';
import 'package:cbec_app/utils/logger.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:get/get_core/src/get_main.dart';

class LeftNavMenu extends StatefulWidget {
  ///菜单列表
  final List<dynamic> list;

  ///激活索引
  final int activeIndex;

  ///点击回调
  final CallBackIndex? onClick;

  ///左侧导航菜单
  const LeftNavMenu(
      {super.key, this.activeIndex = 0, this.onClick, required this.list});

  @override
  State<StatefulWidget> createState() => _LeftNavMenuState();
}

class _LeftNavMenuState extends State<LeftNavMenu> {
  @override
  Widget build(BuildContext context) {
    //获取顶部和底部导航栏高度
    var screenHeight = Get.height;
    var topBarHeight = BaseNavBar().preferredSize.height;
    var bottomBarHeight = 77.h;
    var boxHeight = screenHeight - topBarHeight - bottomBarHeight - 14.h;
    return Container(
        width: 120.w, height: 535.h, color: Colors.white, child: listScroll());
  }
  ///listView滚动形式
  Widget listScroll() {
    return ListView.builder(
        itemCount: widget.list.length,
        itemBuilder: (BuildContext context, int index) {
          return LeftNavMenuItem(
            text: widget.list[index]['className'],
            index: index,
            curIndex: widget.activeIndex,
            onClick: (selectIndex) {
              if (widget.onClick != null) {
                widget.onClick!(selectIndex);
              }
            },
          );
        });
  }
}
